class MyApiController < ApplicationController

  # GET /characters
  # GET /characters.xml
  skip_before_filter :verify_authenticity_token
  # products_controller.rb (in store app)
  before_filter :authorize


  def index
    @common_addresses = CommonAddress.all
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @common_addresses }
      format.json  { render :json => @common_addresses }
    end
  end

  # GET /characters/1
  # GET /characters/1.xml
  def show
    @common_address = CommonAddress.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @common_address }
    end
  end

  # GET /characters/new
  # GET /characters/new.xml
  def new
    @common_address = CommonAddress.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @common_address }
    end
  end

  # GET /characters/1/edit
  def edit
    @common_address = CommonAddress.find(params[:id])
  end

  # POST /characters
  # POST /characters.xml
  def create
    @common_address = CommonAddress.new(params[:c])

    respond_to do |format|
      if @common_address.save
        format.html { redirect_to(@common_address, :notice => 'Character was successfully created.') }
        format.xml  { render :xml => @common_address, :status => :created, :location => @common_address }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @common_address.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /characters/1
  # PUT /characters/1.xml
  def update
    @common_address = CommonAddress.find(params[:id])

    respond_to do |format|
      if @common_address.update_attributes(params[:common_address])
        format.html { redirect_to(@common_address, :notice => 'Character was successfully updated.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @common_address.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /characters/1
  # DELETE /characters/1.xml
  def destroy
    @common_address = CommonAddress.find(params[:id])
    @common_address.destroy

    respond_to do |format|
      format.html { redirect_to(characters_url) }
      format.xml  { head :ok }
    end
  end

  protected

  def authorize
     authenticate_or_request_with_http_basic do |username, password|
        username == "admin" && password == "secret"
     end
  end


end

